package com.example.demo.config;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class CommonConfiguration {




    @Bean
    public ChatMemory chatMemory(){
        return  MessageWindowChatMemory.builder().build();
    }


    @Bean
    public ChatClient chatClient(OpenAiChatModel chatModel,ChatMemory  chatMemory){
        return ChatClient
                .builder(chatModel)
                .defaultSystem("你是百科全书，问你任何问题都能得到快速且准确的解释")
                .defaultAdvisors(new SimpleLoggerAdvisor(),MessageChatMemoryAdvisor.builder(chatMemory).build())
                .build();

    }


//    @Bean
//    public ChatClient chatClient(){
//        var api = new OpenAiApi("https://api.siliconflow.cn/", "sk-tftrzvvzrpdnnranijycrmrhfvtxpiakrpeancwhpdkhjece");
//        return ChatClient.builder(new OpenAiChatModel(api)).build();
//
//    }


}
